package com.im.project.controller;

import com.im.common.result.JsonResult;
import com.im.project.entity.dto.ContactApplyDto;
import com.im.project.entity.dto.DeleteContactDto;
import com.im.project.service.ContactService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 联系人 控制层
 *
 * @author yunZhouJiaDi
 */
@RestController
@RequestMapping("/contact")
@Api(tags = "ContactController", description = "联系人相关接口")
public class ContactController {

    @Resource
    private ContactService contactService;

    @GetMapping("/searchContact")
    @ApiOperation("搜索联系人")
    public JsonResult queryContact(@RequestParam String searchKey) {
        return JsonResult.success(contactService.queryContact(searchKey));
    }

    @PostMapping("/apply")
    @ApiOperation("申请添加联系人或群组")
    public JsonResult apply(@Validated @RequestBody ContactApplyDto contactApplyDto) {
        return JsonResult.success(contactService.apply(contactApplyDto));
    }

    @GetMapping("/userContactList")
    @ApiOperation("当前登录用户的好友列表")
    public JsonResult queryUserContactList() {
        return JsonResult.success(contactService.queryUserContactList());
    }

    @GetMapping("/user/info")
    @ApiOperation("根据id查询联系人(必须是好友)")
    public JsonResult queryContactUserInfo(@RequestParam String contactId) {
        return JsonResult.success(contactService.queryContactUserInfo(contactId));
    }

    @GetMapping("/info")
    @ApiOperation("根据id查询联系人(可以是非好友)")
    public JsonResult QueryContactInfo(@RequestParam String contactId) {
        return JsonResult.success(contactService.queryContactInfo(contactId));
    }

    @PostMapping("/delete")
    @ApiOperation("删除联系人")
    public JsonResult deleteContact(@Validated @RequestBody DeleteContactDto deleteContactDto) {
        return JsonResult.success(contactService.deleteContact(deleteContactDto));
    }

    @PostMapping("/blacked")
    @ApiOperation("拉黑联系人")
    public JsonResult blackedContact(@Validated @RequestBody DeleteContactDto deleteContactDto) {
        return JsonResult.success(contactService.blackedContact(deleteContactDto));
    }

}
